﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Enterprise.Infrastructure.Repository
{
   public abstract class Provider<T> : DataAccess
    {

       public Provider() 
       {
           this.ConnectionString = @"Data Source=MAURICIO-APPLE\SQLEXPRESS;Initial Catalog=Enterprise;Integrated Security=True;Pooling=False";
       }

       public abstract Int64 Criar(T objeto);
       public abstract bool Apagar(long id);
       public abstract bool Atualizar(T objeto);
       public abstract T ObterPorId(long id);
       public abstract int ObterNumeroDeRegistros();

       public abstract List<T> ObterRegistros(int indice, int tamanhoPagina);


       public abstract T PreencherObjeto(IDataReader reader);

       protected virtual List<T> PreencherListaDeObjetos(IDataReader reader) 
       {
           List<T> ListaDeObjetos = new List<T>();
           while (reader.Read()) 
           {
               ListaDeObjetos.Add(PreencherObjeto(reader));
           }
           return ListaDeObjetos;
       }





    }
}
